package com.mayikt.service;

import com.mayikt.entity.UserEntity;
import com.mayikt.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: BuMingBo
 * @ClassName: UserService
 * @create: 2022-05-15 01:54
 * Version: 1.0
 */
@RestController
public class UserService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/insertUser")
    public Boolean insertUser(String name, Integer age) {
        int update = jdbcTemplate.update("insert into users values(null,?,?);", name, age);
        return update > 0 ? true : false;
    }

    /**
     * mybatis 查询
     * @param id
     * @return
     */
    @RequestMapping("/mybatisfindbyId")
    public UserEntity mybatisfindbyId(Integer id){
        return userMapper.selectByUserId(id);
    }

    @RequestMapping("/insertUserMybatis")
    public String insertUserMybatis(String userName, Integer age){
        int insert = userMapper.insertUser(userName, age);
        return insert > 0 ? "success" : "fail";
    }

    @RequestMapping("/myIndex")
    public String myIndex(){
        return "每特1111";
    }
}
